//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_handlemessage.sqf"
#include "x_setup.sqf"

// handles messages  transfered over the network
private ["_msg","_receiver_type","_receiver","_type"];
PARAMS_4(_msg,_receiver_type,_receiver,_type);
if (isNull _receiver) exitWith {};
 //_receiver_type:  "unit", "grp", "all","vec"
 //_receiver: only needed for "unit", "grp", "vec", otherwise objNull
 //_type: "global", "vehicle", "side", "group", "hint", "hq"
switch (_type) do {
	case "global": {
		switch (_receiver_type) do {
			case "unit": {if (player == _receiver) then {systemChat _msg}};
			case "grp": {if (group player == _receiver) then {systemChat _msg}};
			case "all": {systemChat _msg};
			case "vec": {if (player in _receiver) then {systemChat _msg}};
		};
	};
	case "vehicle": {
		switch (_receiver_type) do {
			case "unit": {if (player in _receiver) then {[_receiver,_msg] call FUNC(VehicleChat)}};
			case "grp": {if (player in _receiver) then {[_receiver,_msg] call FUNC(VehicleChat)}};
			case "vec": {if (player in _receiver) then {[_receiver,_msg] call FUNC(VehicleChat)}};
		};
	};
	case "side": {
		switch (_receiver_type) do {
			case "unit": {if (player == _receiver) then {[player,_msg] call FUNC(SideChat)}};
			case "grp": {if (group player == _receiver) then {[player,_msg] call FUNC(SideChat)}};
			case "all": {[player,_msg] call FUNC(SideChat)};
			case "vec": {if (player in _receiver) then {[player,_msg] call FUNC(SideChat)}};
		};
	};
	case "group": {
		switch (_receiver_type) do {
			case "unit": {if (player == _receiver) then {[player,_msg] call FUNC(GroupChat)}};
			case "grp": {if (group player == _receiver) then {[player,_msg] call FUNC(GroupChat)}};
			case "all": {[player,_msg] call FUNC(GroupChat)};
			case "vec": {if (player in _receiver) then {[player,_msg] call FUNC(GroupChat)}};
		};
	};
	case "hint": {
		switch (_receiver_type) do {
			case "unit": {if (player == _receiver) then {hintSilent _msg}};
			case "grp": {if (group player == _receiver) then {hintSilent _msg}};
			case "all": {hintSilent _msg};
			case "vec": {if (player in _receiver) then {hintSilent _msg}};
		};
	};
	case "hq": {
		switch (_receiver_type) do {
			case "unit": {if (player == _receiver) then {_msg call FUNC(HQChat)}};
			case "grp": {if (group player == _receiver) then {_msg call FUNC(HQChat)}};
			case "all": {_msg call FUNC(HQChat)};
			case "vec": {if (player in _receiver) then {_msg call FUNC(HQChat)}};
		};
	};
};